﻿using System;
using System.Linq;
using System.Web.Mvc;
using Citi.Scheduler.Domain;

namespace Citi.Scheduler.WebUi.Controllers
{
    public class ConfigurationController : ControllerBase
    {
        public ActionResult FormPartial()
        {
            var groups = new ConfigurationGroup().SelectAllActive<ConfigurationGroup>();
            ViewBag.ConfigurationGroups = groups.ToSelectList(x => x.Name, x => x.Id.ToString());

            var configs = new Configuration().SelectAllActive<Configuration>().Where(x => x.ConfigurationGroupId == groups.First().Id);
            ViewBag.Configurations = configs.ToSelectList(x => x.Name, x => x.Id.ToString());

            return PartialView();
        }

        public ActionResult LoadConfigurationByGroup(int configurationGroupId)
        {
            var configs = new Configuration().SelectAllActive<Configuration>().Where(x => x.ConfigurationGroupId == configurationGroupId);

            return Json(configs.Select(x => new { value = x.Id, text = x.Name }), JsonRequestBehavior.AllowGet);
        }
    }
}
